<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新增供应商</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.4.4.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.validate.method.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/messages_cn.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/json2.js"></script>
<style type="text/css">
    body{ font-size:12px;}
    .l-table-edit {}
    .l-table-edit-td{ padding:4px;}
    .l-button-submit,.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
    .l-verify-tip{ left:230px; top:120px;}
    .p-tab .s-lab{font-size:12px;font-family:"微软雅黑",​"宋体",​Arial,​sans-serif;}
	input.l-textarea{width:170px;height:20px;font-size:12px;}
	 .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
	/*gjf xinzeng*/
		.formtips{width: 200px;margin:2px;padding:2px;}
	.onError{
	    background:#FFE0E9 url(../img/reg3.gif) no-repeat 0 center;
		padding-left:25px;
	}
	.onSuccess{
	    background:#E9FBEB url(../img/reg4.gif) no-repeat 0 center;
		padding-left:25px;
	}
	.high{
	    color:red;
	}
	
</style>
</head>
<body style="padding:10px">
<div class="navbar">
		<span>您当前的位置：</span>
		基础数据管理&gt;供应商管理 &gt;新增供应商
</div>
<form name="form1" method="post" action="c_supplierInfo.do" id="form1">
<input id=conBrandArr type="hidden" name="conBrandArr" >
<input id=purBrandArr type="hidden" name="purBrandArr" >
<input id="today" type="hidden" name="today" size="13" class="Wdate" readonly="readonly" value="">
<br>
<table cellpadding="0" cellspacing="0" class="l-table-edit p-tab" >
	
	 <tr>
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font>供应商编号：</td>
        <td align="left" class="l-table-edit-td s-lab"><input  name="account" id="account"  type="text" class="l-textarea" maxlength="5" id="account"  /></td>
        <td align="left"><span style="color:red" id="error"></span></td>
    </tr>
    <tr>
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font>供应商名称：</td>
        <td align="left" class="l-table-edit-td s-lab"><input name="supName"  type="text" class="l-textarea" id="supName" maxlength="20" validate="{required:true,minlength:1,maxlength:20}" /></td>
        <td align="left"></td>
    </tr>
     <tr>
        <td align="right" class="l-table-edit-td s-lab">供应商简称：</td>
        <td align="left" class="l-table-edit-td s-lab"><input name="supShortName" type="text" class="l-textarea"  maxlength="20" id="supShortName" validate="{minlength:1,maxlength:20}" /></td>
        <td align="left"></td>
    </tr>
     <tr style="display: none">
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font>供应商编号：</td>
        <td align="left" class="l-table-edit-td s-lab"><input name="supCode" type="text" id="supCode" maxlength="20"  class="l-textarea" validate="{minlength:1,maxlength:20}" /></td>
        <td align="left"></td>
    </tr>
    <tr>
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font>联系人：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
        <input id="linkman" type="text" name="linkman"  class="l-textarea" maxlength="20" validate="{required:true,minlength:1,maxlength:20}">
        </td><td align="left"></td>
    </tr>
    <tr>
        <td align="right" class="l-table-edit-td s-lab">固定电话：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
        <input id="telephoneNum" type="text" name="telephoneNum"  class="l-textarea" validate="{phone:true}">
        </td><td align="left"></td>
    </tr>
     <tr>
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font>手机号码：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
        <input id="mobileNhonenum" type="text" name="mobileNhonenum"  class="l-textarea"  validate="{required:true,minlength:11,maxlength:11}">
        </td><td align="left"></td>
    </tr>
    <tr>
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font>经营类别：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
        <input id="operateTpye" type="text" name="operateTpye" maxlength="20" class="l-textarea"  validate="{required:true}">
        </td><td align="left"></td>
    </tr>
     <tr>
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font>电子邮箱：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
        <input id="email" type="text" name="email"  maxlength="50" class="l-textarea" validate="{required:true,email:true,rangelength:[1,50]}">
        </td><td align="left"></td>
    </tr>
     <tr>
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font>合同开始日期：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
       <input type="text" name="contractDayStrat" id="contractDayStrat"
    	 validate="{required:true}" class="l-textarea" class="Wdate"  size="18"onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,maxDate:'#F{$dp.$D(\'contractDayEnd\')||\'2020-10-01\'}'})"/>
        </td><td align="left"></td>
    </tr>
    <tr>
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font>合同结束日期：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
       <input type="text" name="contractDayEnd" id="contractDayEnd"
    	 validate="{required:true}" class="l-textarea" class="Wdate"  size="18"onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,minDate:'#F{$dp.$D(\'contractDayStrat\')||\'2013-01-01\'}'})"/>
        </td><td align="left"></td>
    </tr>
     <tr>
        <td align="right" class="l-table-edit-td s-lab">联系地址：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
        <input id="address" type="text" name="address" maxlength="100" class="l-textarea"  validate="{minlength:1,maxlength:100}">
        </td><td align="left"></td>
    </tr>
    <!-- <tr>
        <td align="right" class="l-table-edit-td s-lab">
                     结算类型：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
         
        </td><td align="left" class="l-table-edit-td s-lab"></td>
        <td align="left" class="l-table-edit-td s-lab"></td>
    </tr> 
    <tr>
        <td align="right" class="l-table-edit-td s-lab"> 代销结算：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
        <input type="button" name ="daiButton" value="选择品牌"  class="l-button l-button-submit" id="daiButton" onclick="javascript:brandList(1);"/>
        </td><td align="left" class="l-table-edit-td s-lab"></td>
    </tr>-->
</table>
<!-- <div id="maingrid1" style="margin-top: 0px; margin-left: 105px; padding: 0"></div>-->
<table cellpadding="0" cellspacing="0" class="l-table-edit p-tab" >
	<tr>
        <td align="right" class="l-table-edit-td s-lab">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="red">*</font>关联品牌：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
        <input type="button" name ="daiButton" value="选择品牌"  class="l-button l-button-submit" id="daiButton" onclick="javascript:brandList(2);"/>
        </td><td align="left" class="l-table-edit-td s-lab"></td>
    </tr>
</table>
<div id="maingrid2" style="margin-top: 0px; margin-left: 105px; padding: 0"></div>
<input type="hidden" name="aslist" id="aslist" />
<input type="submit" value="保存" id="Button1" class="l-button l-button-submit" /> 
<input type="button" value="取消" name="tests"  id="tests" class="l-button l-button-test" />
</form>
<div style="display:none">
<!--  数据统计代码 --></div>

<script type="text/javascript">
	var basePath='${BasePath}';
	var conGrid = null;
	var purGrid = null;
	var brandJson = [];
	var brandSize = 0;
	var conBrandArr = new Array();
	var purBrandArr = new Array();
	$(function () {
		var today = new Date();
		var tomorrow = new Date(today.setDate(today.getDate() + 1)).format("yyyy-MM-dd");
		$('#today').val(tomorrow);
		showConsignmentBrandList();
		showPurchaseBrandList();
	});

	function showConsignmentBrandList() {
		if (brandJson.length > 0) {
			var brandObj = null;
			$.each(brandJson,function(id) {
	    		if (!checkBrandExists(brandJson[id], 1)) {
	    			brandObj = new Object();
	    			brandObj.brandName = brandJson[id].brandName;
	    			brandObj.brandNo = brandJson[id].no;
	    			brandObj.accountsTime = '';
	    			brandObj.accountsWay = '';
	    			brandObj.pointsScale = '';
	    			conBrandArr.push(brandObj);
	    		}
			});
		}
		consignmentBrandData = {"Rows": conBrandArr, "Total": conBrandArr.length};
		/* conGrid = $("#maingrid1").ligerGrid({
	           columns: [
	           { display: '品牌名称',isSort: false, name: 'brandName'},
	           { display: '品牌编码',isSort: false, name: 'brandNo'},
	           { display: '结算周期',isSort : false,render  : function(rowdata,rowindex,value){
	        		  var text = "<select name='conAccountsTime' id='conAccountsTime" + rowdata.brandNo + "' class='l-textarea' onchange='javascript:accountsTimeChange(" + rowindex + ", 1)'>";
	        		  if (rowdata.accountsTime == '') {
	        			  text += "<option value=''>请选择</option>";
	        		      text += "<option value='1'>月结15天</option>";
	        		      text += "<option value='2'>月结30天</option>";
	        		  } else if (rowdata.accountsTime == '1') {
	        		      text += "<option value='1'>月结15天</option>";
	        			  text += "<option value=''>请选择</option>";
	        		      text += "<option value='2'>月结30天</option>";
	        		  } else if (rowdata.accountsTime == '2') {
	        		      text += "<option value='2'>月结30天</option>";
	        			  text += "<option value=''>请选择</option>";
	        		      text += "<option value='1'>月结15天</option>";
	        		  }
	        		  text += "</select>";
        		      return text;
	        	  }
	           },
	           {
		        display: '结算方式',isSort : false,width:'12%',render : function(rowdata,rowindex,value){
		        		  var text = "<select name='accountsWay' id='accountsWay" + rowdata.brandNo + "' class='l-textarea' onchange='javascript:accountsWayChange(" + rowindex + ")'>";
		        		  if (rowdata.accountsWay == '') {
	        		    	  text += "<option value=''>请选择</option>";
		        		      text += "<option value='1'>扣点</option>";
		        		      text += "<option value='2'>底价</option>";
	        		      } else if (rowdata.accountsWay == '1') {
		        		      text += "<option value='1'>扣点</option>";
	        		    	  text += "<option value=''>请选择</option>";
		        		      text += "<option value='2'>底价</option>";
	        		      } else if (rowdata.accountsWay == '2') {
		        		      text += "<option value='2'>底价</option>";
	        		    	  text += "<option value=''>请选择</option>";
		        		      text += "<option value='1'>扣点</option>";
	        		      }
	        		      text += "</select>";
	        		      return text;
		        	  }
		       },
		       { display: '扣点比例(%)',isSort: false, render: function(rowdata,rowindex,value){
		    	   var text = "";
		    	   if (typeof(rowdata.pointsScale) == 'undefined' || rowdata.pointsScale == '') {
		    		   text = "<input name='pScale"  + rowdata.brandNo + "' id='pScale" + rowdata.brandNo + "' class='l-textarea' style='width: 100px;' disabled='disabled' onblur='javascript:fillPScale(" + rowindex + ");'/>";
		    	   } else {
		    		   text = "<input name='pScale"  + rowdata.brandNo + "' id='pScale" + rowdata.brandNo + "' value='" + rowdata.pointsScale + "' class='l-textarea' style='width: 100px;' onblur='javascript:fillPScale(" + rowindex + ");'/>";
		    	   }
		    	   return text;
		       } },
	           { display: '操作', isSort: false,width:'12%', render: function (rowdata, rowindex, value){
	        	    var h = "";
	        	    h += "<a href='javascript:deleteRow(" + rowindex + ", 1)'>删除</a> ";
	               return h;
	           	}
	           }
	           
	           ], 
	           pageSize:30,
	           width: '60%',
	           data: $.extend(true,{},consignmentBrandData)
	       });
		brandJson = []; */
	}

	function showPurchaseBrandList() {
		if (brandJson.length > 0) {
			var brandObj = null;
			$.each(brandJson,function(id) {
	    		if (!checkBrandExists(brandJson[id], 2)) {
	    			brandObj = new Object();
	    			brandObj.brandName = brandJson[id].brandName;
	    			brandObj.brandNo = brandJson[id].no;
	    			brandObj.accountsTime = '';
	    			purBrandArr.push(brandObj);
	    		}
			});
		}
		purchaseBrandData = {"Rows": purBrandArr, "Total": purBrandArr.length};
		purGrid = $("#maingrid2").ligerGrid({
	           columns: [
	           { display: '品牌名称',isSort: false, name: 'brandName'},
	           { display: '品牌编码',isSort: false, name: 'brandNo'},
	           /* { display: '结算周期',isSort : false,render : function(rowdata,rowindex,value){
	        	   var text = "<select name='accountsTime' id='purAccountsTime" + rowdata.brandNo + "' class='l-textarea' onchange='javascript:accountsTimeChange(" + rowindex + ", 2)'>";
     		      if (rowdata.accountsTime == '') {
     		    	  text += "<option value=''>请选择</option>";
	        		      text += "<option value='1'>预付</option>";
	        		      text += "<option value='2'>货到7天</option>";
	        		      text += "<option value='3'>货到15天</option>";
	        		      text += "<option value='4'>货到30天</option>";
	        		      text += "<option value='5'>月结15天</option>";
	        		      text += "<option value='6'>月结30天</option>";
     		       } else if (rowdata.accountsTime == '1') {
	        		      text += "<option value='1'>预付</option>";
     		    	  text += "<option value=''>请选择</option>";
	        		      text += "<option value='2'>货到7天</option>";
	        		      text += "<option value='3'>货到15天</option>";
	        		      text += "<option value='4'>货到30天</option>";
	        		      text += "<option value='5'>月结15天</option>";
	        		      text += "<option value='6'>月结30天</option>"; 
     		      } else if (rowdata.accountsTime == '2') {
	        		      text += "<option value='2'>货到7天</option>";
     		    	  text += "<option value=''>请选择</option>";
	        		      text += "<option value='1'>预付</option>";
	        		      text += "<option value='3'>货到15天</option>";
	        		      text += "<option value='4'>货到30天</option>";
	        		      text += "<option value='5'>月结15天</option>";
	        		      text += "<option value='6'>月结30天</option>";
     		      } else if (rowdata.accountsTime == '3') {
	        		      text += "<option value='3'>货到15天</option>";
     		    	  text += "<option value=''>请选择</option>";
	        		      text += "<option value='1'>预付</option>";
	        		      text += "<option value='2'>货到7天</option>";
	        		      text += "<option value='4'>货到30天</option>";
	        		      text += "<option value='5'>月结15天</option>";
	        		      text += "<option value='6'>月结30天</option>";
     		      } else if (rowdata.accountsTime == '4') {
	        		      text += "<option value='4'>货到30天</option>";
     		    	  text += "<option value=''>请选择</option>";
	        		      text += "<option value='1'>预付</option>";
	        		      text += "<option value='2'>货到7天</option>";
	        		      text += "<option value='3'>货到15天</option>";
	        		      text += "<option value='5'>月结15天</option>";
	        		      text += "<option value='6'>月结30天</option>";
     		      } else if (rowdata.accountsTime == '5') {
	        		      text += "<option value='5'>月结15天</option>";
     		    	  text += "<option value=''>请选择</option>";
	        		      text += "<option value='1'>预付</option>";
	        		      text += "<option value='2'>货到7天</option>";
	        		      text += "<option value='3'>货到15天</option>";
	        		      text += "<option value='4'>货到30天</option>";
	        		      text += "<option value='6'>月结30天</option>";
     		      } else if (rowdata.accountsTime == '6') {
	        		      text += "<option value='6'>月结30天</option>";
     		    	  text += "<option value=''>请选择</option>";
	        		      text += "<option value='1'>预付</option>";
	        		      text += "<option value='2'>货到7天</option>";
	        		      text += "<option value='3'>货到15天</option>";
	        		      text += "<option value='4'>货到30天</option>";
	        		      text += "<option value='5'>月结15天</option>";
     		      }
    		      	  text += "</select>";
     		      return text;
		        	  }
		       }, */
	           { display: '操作', isSort: false, render: function (rowdata, rowindex, value){
	        	    var h = "";
	        	    h += "<a href='javascript:deleteRow(" + rowindex + ", 2)'>删除</a> ";
	               return h;
	           	}
	           }
	           ], 
	           pageSize:30,
	           width: '60%',
	           data: $.extend(true,{},purchaseBrandData)
	       });
		brandJson = [];
	}

   $(function ()
		{
	   
	   jQuery.validator.addMethod("accountStr", function(value, element) {
			return this.optional(element) || /^[0-9]\d*|0$/.test(value);
		}, "请输入数字字符");
	   
			jQuery.validator.addMethod("account_exit",function(value,element){
				var account=$("#account").val();
				var rst = false;
				  $.ajax({
						type:"POST",
						url:"../../base/supplierInfo/checkAccount.do",
						data:{"account":account},
						async : false,
						success:function(data){
							if(data=="fail"){
								rst = false;
							}else{
								rst = true;
							}
						}
					});
				  return this.optional(element) || rst;
			
			   },"该编号已存在，请重输入");
			
			
			jQuery.validator.addMethod("supName_exit",function(value,element){
				var supName=$("#supName").val();
				var rst = false;
				  $.ajax({
						type:"POST",
						url:"../../base/supplierInfo/checkSupName.do",
						data:{"supName":supName},
						async : false,
						success:function(data){
							if(data=="fail"){
								rst = false;
							}else{
								rst = true;
							}
						}
					});
				  return this.optional(element) || rst;
			
			   },"该供应商名称已存在，请重输入");	
			
			//validate
		    $.metadata.setType("attr", "validate");
		    var v = $("form").validate({
		    	rules: {
		    		"account": {required: true,accountStr:true,minlength:5,account_exit:true},
		    		"supName": {required: true,supName_exit:true}
		    	},
		    	messages: {
		    		"account": {
		    			required: "该字段不能为空",
		    			accountStr: "请输入数字字符",
		    			minlength: "请输入5位编号字符",
		    			account_exit: "该编号已存在，请重输入"
		    		},
		    		"supName": {
		    			required: "该字段不能为空",
		    			supName_exit: "该供应商名称已存在，请重输入"
		    		}
		    	},
		        errorPlacement: function (lable, element)
		        {
		            if (element.hasClass("l-textarea"))
		            {
		            	try{
		            		lable.ligerHideTip();
		            		element.ligerTip({ content: lable.html(), target: element[0] });
	            		}catch(e){}
		            }
		            else if (element.hasClass("l-text-field"))
		            {
		            	try{
		            		lable.ligerHideTip();
		            		element.parent().ligerTip({ content: lable.html(), target: element[0] });
	            		}catch(e){}
		            }
		            else
		            {
		                lable.appendTo(element.parents("td:first").next("td"));
		            }
		        },
		        success: function (lable)
		        {
		        	try{lable.ligerHideTip();}catch(e){}
		            lable.remove();
		        },
		        submitHandler:function()
		        {
		        	if (conBrandArr.length == 0 && purBrandArr.length == 0) {
		        		$.ligerDialog.warn("请设置最少一种关联的品牌");
		            	return false;
		        	}
		        	/* 
		            if (conBrandArr.length > 0) {
		            	var i = 0;
		            	$.each(conBrandArr, function(id) {
		       			 if (conBrandArr[id].accountsTime == '' || conBrandArr[id].accountsWay == '' || 
		       					 (conBrandArr[id].accountsWay == '1' && conBrandArr[id].pointsScale == '') ||
		       					 (conBrandArr[id].accountsWay == '1' && !/^[0-9]+(\.[0-9]{0,2})?$/.test(conBrandArr[id].pointsScale)) ||
		       					 (conBrandArr[id].accountsWay == '1' && parseFloat(conBrandArr[id].pointsScale)) > 100.0) {
		       				 i++;
		       				 return false;
		       			 }
		       		 	});
		            	if (i > 0) {
		            		$.ligerDialog.warn("代销结算还有参数未设置或未设置正确(当结算方式为扣点时扣点比例应为0到100的最多两位小数的数值)");
		            		return false;
		            	}
		            }
					if (purBrandArr.length > 0) {
						var i = 0;
						$.each(purBrandArr, function(id) {
			       			 if (purBrandArr[id].accountsTime == '') {
			       				 i++;
			       				 return false;
			       			 }
						});
						if (i > 0) {
							$.ligerDialog.warn("购销结算还有参数未设置");
		            		return false;
		            	}
		            } 
					*/
					$('#conBrandArr').val(JSON.stringify(conBrandArr));
					$('#purBrandArr').val(JSON.stringify(purBrandArr));
		            var options = {
		            		type: 'POST',
		            		beforeSend: function(){
		            			$("#form1").find(":submit,:button").attr("disabled", true);
		            		},
		            		success: function(data){
		            			if(data=="success") {
		            				window.parent.f_tip('新增成功');
		            				window.location.href="../../base/supplierInfo/pageFinderSupplier.do";
		           					close_liger_tab();
		            			}else if(data=="wms_fail"){
		            				window.parent.f_tip('WMS系统推送数据失败');
		            			}else {
		            				window.parent.f_tip('新增失败');
		            			}
		            		}
		            	}, $form1 = $("#form1");
		           $form1.ajaxSubmit(options);
		             return false;
		        }
		    });
		}); 
		
 function brandList(num){
	  var m=$.ligerDialog.open({title:'选择品牌',url:basePath+'/base/supplierInfo/toBrandList.do',height:500,width:700,isResize: false, isDrag: false,
		buttons: [{ text: '确定', onclick: function (item, dialog) { 
			dialog.frame.addBrand(); 
			if(dialog.frame.isSuccess == "success"){
				if (num == 1) {
					showConsignmentBrandList();
				} else {
					showPurchaseBrandList();
				}
				dialog.close();
			}
	  }},
      { text: '取消', onclick: function (item, dialog) { 
    	  dialog.close(); } 
	  }]});
	  m.show(); 
  }
 
 function accountsWayChange(rowindex) {
	 var brand = conGrid.getRow(rowindex);
	 $.each(conBrandArr, function(id) {
		 if (conBrandArr[id].brandNo == brand.brandNo) {
			 conBrandArr[id].accountsWay = $('#accountsWay' + brand.brandNo).val();
			 return false;
		 }
	 });
	 if ($('#accountsWay' + conGrid.getRow(rowindex).brandNo).val() == '1') {
		 $('#pScale' + conGrid.getRow(rowindex).brandNo).removeAttr('disabled');
	 } else {
		 $('#pScale' + conGrid.getRow(rowindex).brandNo).val('');
		 $('#pScale' + conGrid.getRow(rowindex).brandNo).attr('disabled', 'disabled');
	 }
 }
 
 function accountsTimeChange(rowindex, num) {
	 if (num == 1) {
		 var brand = conGrid.getRow(rowindex);
		 $.each(conBrandArr, function(id) {
			 if (conBrandArr[id].brandNo == brand.brandNo) {
				 conBrandArr[id].accountsTime = $('#conAccountsTime' + brand.brandNo).val();
				 return false;
			 }
		 });
	 } else {
		 var brand = purGrid.getRow(rowindex);
		 $.each(purBrandArr, function(id) {
			 if (purBrandArr[id].brandNo == brand.brandNo) {
				 purBrandArr[id].accountsTime = $('#purAccountsTime' + brand.brandNo).val();
				 return false;
			 }
		 });
	 }
 }
 
 function fillPScale(rowindex) {
	 var brand = conGrid.getRow(rowindex);
	 $.each(conBrandArr, function(id) {
		 if (conBrandArr[id].brandNo == brand.brandNo) {
			 conBrandArr[id].pointsScale = $('#pScale' + brand.brandNo).val();
			 return false;
		 }
	 });
 }
 
 function checkBrandExists(brand, num) {
	var i = 0;
	if (num == 1) {
		if (conBrandArr.length > 0) {
	 		$.each(conBrandArr,function(id) {
	 			if (conBrandArr[id].brandNo == brand.no) {
	 				i++;
	 			}
	 		});
	 		if (i > 0) {
	 			return true;
	 		} else {
	 			return false;
	 		}
	 	} else {
	 		return false;
	 	}
	} else {
		if (purBrandArr.length > 0) {
	 		$.each(purBrandArr,function(id) {
	 			if (purBrandArr[id].brandNo == brand.no) {
	 				i++;
	 			}
	 		});
	 		if (i > 0) {
	 			return true;
	 		} else {
	 			return false;
	 		}
	 	} else {
	 		return false;
	 	}
	}
 }
 
 function deleteRow(rowindex, num) {
	 $.ligerDialog.confirm('确定删除', function(yes) {
		 if (yes) {
			 if (num == 1) {
				 if (conBrandArr.length > 0) {
					 var brand = conGrid.getRow(rowindex);
					 $.each(conBrandArr, function(id) {
						 if (conBrandArr[id].brandNo == brand.brandNo) {
							 conBrandArr.splice(id, 1);
							 showConsignmentBrandList();
							 return false;
						 }
					 });
				 }
			 } else {
				 if (purBrandArr.length > 0) {
					 var brand = purGrid.getRow(rowindex);
					 $.each(purBrandArr, function(id) {
						 if (purBrandArr[id].brandNo == brand.brandNo) {
							 purBrandArr.splice(id, 1);
							 showPurchaseBrandList();
							 return false;
						 }
					 });
				 }
			 }
		 }
	 });
 }
		
// 取消
$("#tests").click(function() {
	close_liger_tab();
	
});	

//日期格式化
Date.prototype.format = function(format) {
	var o = {
		"M+" : this.getMonth()+1, //month
		"d+" : this.getDate(),    //day
		"H+" : this.getHours(),   //hour
	 	"m+" : this.getMinutes(), //minute
		"s+" : this.getSeconds(), //second
	 	"q+" : Math.floor((this.getMonth()+3)/3),  //quarter
	 	"S" : this.getMilliseconds() //millisecond
	};

	if(/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	for(var k in o) {
		if(new RegExp("("+ k +")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return format;
};

</script>
</body>
</html>